# coding=utf-8
import uuid

from django.contrib.auth.models import AbstractUser
from django.db import models

from utils.date_scraper import now


class User(AbstractUser):
    # 手机号
    phone_number = models.CharField(max_length=20, blank=True)
    # 性别
    gender = models.CharField(max_length=20, blank=True)
    # 真实姓名
    zsxm = models.CharField(max_length=20, blank=True)
    # 身份证号
    sfzh = models.CharField(max_length=11, blank=True)
    # 注册城市
    zccs = models.CharField(max_length=10, blank=True)
    # 头像，OSS存储头像的url，不填则给出默认头像url
    avatar = models.CharField(max_length=100, blank=True,
                              default="http://www.baidu.com")
    # 类型 供后台判断
    usertype = models.CharField(max_length=5,
                                choices=(('worker', '工人'),
                                         ('boss', '老板')))

    is_deleted = models.BooleanField(default=False)
    created_time = models.BigIntegerField(default=now)
    uuid = models.SlugField(default=uuid.uuid1, unique=True)

    class Meta:
        db_table = "system_user"


class WorkerUser(models.Model):
    """"劳工表"""
    user = models.OneToOneField(User)
    # 银行卡号
    yhkh = models.CharField(max_length=20, blank=True)
    # 平均评分
    star = models.IntegerField(default=100)
    # TODO 工种
    # 是否驾驶证
    jsz = models.BooleanField(default=False)
    # 驾龄
    jl = models.IntegerField(default=0)
    # 是否健康证
    jkz = models.BooleanField(default=False)


class BossUser(models.Model):
    """"商家/工头"""
    user = models.OneToOneField(User)
    # 公司名称
    gsmc = models.CharField(max_length=50, blank=True)
    # 纳税人识别号
    nsrsbh = models.CharField(max_length=50, blank=True)
    # 工商注册号
    gszch = models.CharField(max_length=50, blank=True)
    # 常用施工地址
    cysgdz = models.CharField(max_length=50, blank=True)


class OperationLog(models.Model):
    # 用户进行的操作类型
    type = models.CharField(blank=True, max_length=50)
    # 用户进行操作的手机唯一识别号
    device_uuid = models.CharField(blank=True, max_length=50)
    # User-Agent
    ua = models.CharField(blank=True, max_length=100)
    # 手机类型
    mobile_type = models.CharField(max_length=10, choices=(('android', '安卓'), ('ios', 'iOS'), ('unknown', '未知')))
    # 进行操作的用户
    user = models.ForeignKey(User, related_name='user', null=True, blank=True)
    # 进行操作的时间
    time = models.BigIntegerField(default=now)
    # 用户进行操作的ip地址
    ip = models.CharField(max_length=16, default='0.0.0.0')
